package cn.admin.configcenter.registry.common.event;

import cn.admin.config.common.protocol.Swizzle;
import cn.admin.configcenter.registry.common.info.ClientConnection;
import cn.admin.configcenter.registry.common.info.GroupId;

import java.util.Collections;
import java.util.List;

public class Events {

    public static class NonPersistDataPublishedEvent extends Event {
        public final ClientConnection client;
        public final GroupId group;
        public final Swizzle data;

        public NonPersistDataPublishedEvent(ClientConnection client,GroupId group,Swizzle data) {
            this.client = client;
            this.group = group;
            this.data = data;
        }

        @Override
        protected List<Event> implyEvents() {
            return Collections.emptyList();
        }
    }

    public static class NonPersistPublisherRemovedEvent extends Event {

        public final ClientConnection client;
        public final GroupId group;

        public NonPersistPublisherRemovedEvent(ClientConnection client,GroupId group) {
            this.client = client;
            this.group = group;
        }

        @Override
        protected List<Event> implyEvents() {
            return Collections.emptyList();
        }
    }

    public static class ClientDisconnectedEvent extends Event {

        public final ClientConnection client;

        public ClientDisconnectedEvent(ClientConnection client) {
            this.client = client;
        }

        @Override
        protected List<Event> implyEvents() {
            return Collections.emptyList();
        }
    }

    public static class GroupDataMannualChangedEvent extends GroupDataChangedEvent {

        public GroupDataMannualChangedEvent(GroupId group) {
            super(group);
        }
    }

    public static class GroupDataChangedEvent extends Event {

        public final GroupId group;

        public GroupDataChangedEvent(GroupId groupId) {
            this.group = groupId;
            group.increaseRevision();
        }

    }

    public static class SubscriberAddedEvent extends Event {

        public final ClientConnection client;
        public final GroupId group;
        public final long createTime = System.currentTimeMillis();

        public SubscriberAddedEvent(ClientConnection client,GroupId group) {
            this.client = client;
            this.group = group;
        }

    }


}
